package com.loser.sale.handler;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.loser.module.base.common.ApiResponse;
import com.loser.rpc.sale.dto.resp.UserBalanceResp;
import com.loser.sale.mysql.entity.UserBalance;
import com.loser.sale.mysql.service.UserBalanceService;
import com.loser.utils.ParamsUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class UserBalanceHandler {

    @Autowired
    private UserBalanceService userBalanceService;

    public ApiResponse<UserBalanceResp> getByUserId(Long userId) {
        LambdaQueryWrapper<UserBalance> query = Wrappers.<UserBalance>lambdaQuery().eq(UserBalance::getUserId, userId);
        UserBalance userBalance = userBalanceService.getOne(query);
        log.info("getByUserId {}", userBalance);
        return ApiResponse.ok(ParamsUtil.copyProperties(userBalance, UserBalanceResp.class));
    }

}

